/******************************************************************************
** @file	test_sqlite3x_reader.cpp
** @author  Joel Chuca Condo
**
** @date	Sep 01, 2010
**
** @desc	This testSuite tests the creating of database and tables.
*			
******************************************************************************/

#include "unit--/unit--.h"
#include "sqlite3x.hpp"

#include <iostream>
#include <stdexcept>

using namespace sqlite3x;
using namespace unit_minus;
using namespace std;

testSuite(DatabaseLayer);

testCase(readerDatabaseTest, DatabaseLayer)
{
    sqlite3_connection con("test.db");
   
    string script = "CREATE TABLE test_table ( "
        "id  integer PRIMARY KEY AUTOINCREMENT NOT NULL, "
        "name        varchar(255) , "
        "wname        varchar(255), "
        "installDate integer );";
    con.executenonquery(script);

    sqlite3_transaction trans(con);
	{
		sqlite3_command cmd(con, "insert into test_table (id, name, wname, installDate)values(NULL,?,?,?);");
		cmd.bind(1, "name01", 6);
        cmd.bind(2, wstring(L"name01"));
        cmd.bind(3, 1092941466);            
		cmd.executenonquery();		
	}
    trans.commit();

    string nameTest = "name01";
    wstring wnameTest = L"name01";
    long long longDateTest = 1092941466;

    sqlite3_command cmd(con, "select * from test_table where id=?;");
    cmd.bind(1,1);
    sqlite3_reader reader=cmd.executereader();

    if(reader.read())
    {
        string name = reader.getstring(1);
        assertTrue(nameTest == name);
        wstring wname = reader.getstring16(2);
        assertTrue(wnameTest == wname);
        long long longdate = reader.getint64(3);
        assertTrue(longDateTest == longdate);
    }

    //con.close();
}